
import 'package:flutter/material.dart';
import '../model/home_model.dart';
import 'fwebview.dart';


class SubNav extends StatelessWidget {
  final List<CommonModel> subNavList;
  const SubNav({super.key,required this.subNavList});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6),
        color: Colors.white,
      ),
        child: _items(context),

    );
  }

  Widget _items(BuildContext context){

    if (subNavList == null){
      return Container();
    }
    int separate = (subNavList!.length / 2 + 0.5).toInt();
    List<Widget> list = [];
    subNavList!.forEach((value) {
      list.add(_item(context, value));
    });
    return Container(
      padding: EdgeInsets.all(7),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(6),
        color: Colors.white,
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: list.sublist(0,separate),
          ),
          Padding(
            padding: EdgeInsets.only(top: 10),
            child:  Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: list.sublist(separate,list.length),
            ),
          ),
        ],
      ),
    );

  }

  _item(BuildContext context,CommonModel e){
   return Expanded(
     flex: 1,
       child: GestureDetector(
         onTap: (){
           Navigator.push(context,MaterialPageRoute(builder: (context) => FWebView(url: e.url,title: e.title,statusBarColor: e.statusBarColor,hideAppBar: e.hideAppBar,)));
         },
         child: Column(
       children: [
       Image.network(
       e.icon!,
         width: 18,
         height: 18,
       ),
     Padding(
       padding: EdgeInsets.only(top: 3),
       child: Text(
         e.title!,
         style: TextStyle(fontSize: 12,),
       ),
     )
     ],
   ),
       ),
   );
  }
}



